package com.treeroot.queue;

import java.util.Scanner;

public class ArrayQueueDemo {
    public static void main(String[] args) {
        ArrayQueue arrayQueue = new ArrayQueue(3);
        //接收用户输入
        char key;
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("s(show):-----显示队列-----");
            System.out.println("a(add):-----添加数据到队列-----");
            System.out.println("g(get):-----从队列取出数据-----");
            System.out.println("h(head):-----查看队列头的数据-----");
            System.out.println("e(exit):-----退出程序-----");
            key = scanner.next().charAt(0);//接收一个字符
            switch (key) {
                case 's':
                    arrayQueue.showQueueData();
                    break;
                case 'a':
                    System.out.println("请输入一个数字");
                    int value = scanner.nextInt();
                    try {
                        arrayQueue.addQueueData(value);
                        System.out.println("添加成功");
                    } catch (RuntimeException e) {
                        System.out.println(e.getMessage());
                    }
                    break;
                case 'g':
                    try {
                        int res = arrayQueue.getQueueDate();
                        System.out.printf("取出的数据是%d\n", res);
                    } catch (RuntimeException e) {
                        System.out.println(e.getMessage());
                    }
                    break;
                case 'h':
                    try {
                        arrayQueue.showHeadData();
                    } catch (RuntimeException e) {
                        System.out.println(e.getMessage());
                    }
                    break;
                case 'e':
                    scanner.close();
                    System.exit(0);
                    break;
                default:
                    break;
            }
        }
    }
}
